package com.faiz.algorithm;


public class TreeNode {
    public TreeNode left;
    public TreeNode right;
    public int val;

    public TreeNode(int val) {
        this.val = val;
    }

    public TreeNode(TreeNode left, TreeNode right, int val) {
        this.left = left;
        this.right = right;
        this.val = val;
    }

    public static TreeNode of(Integer[] array, int index) {
            TreeNode root = null;
            if (index < array.length) {
                Integer value = array[index];
                if (value != null) {
                    root = new TreeNode(value);
                    root.left = of(array, 2 * index + 1);
                    root.right = of(array, 2 * index + 2);
                }
            }
            return root;

    }
}
